﻿//***************************************************
//
//       File Name:    BianXingJingGang.cs
//
//       Author:   王文军    Email:  546527816@qq.com
//
//
//***************************************************

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using XHFrameWork;

public class BianXingJingGang : MonoBehaviour {

    private Vector3 myLocalPostion;
    private Vector3 myLocalScale;
    private Quaternion myRotation;
    private Transform luenzi1;
    private Transform luenzi2;
    private Transform luenzi3;
    private Transform luenzi4;

    private Camera uiCamera;
    public VehicleInfo vehicleInfo;
    private Transform cheShen;
    private Transform cheShenF;
    private Transform cheShenL;
    private float showTime = 8f;
    private bool isShow = true;

    //各种组件是否显示
    private bool isNewAppearanceShow = true;
    private bool isNewPowerShow = true;
    private bool isNewMaterialShow = true;
    private bool isNewEngineShow = true;
    private bool isNewDirectionShow = true;
    private bool isRotate = true;
    private bool isZoom = false;
    private GameObject materialEffect;

    public bool IsZoom
    {
        set { isZoom = value; }
    }
    public bool IsNewAppearanceShow
    {
        set { isNewAppearanceShow = value; }
    }
    public bool IsNewPowerShow
    {
        set { isNewPowerShow = value; }
    }
    public bool IsNewMaterialShow
    {
        set { isNewMaterialShow = value; }
    }
    public bool IsNewEngineShow
    {
        set { isNewEngineShow = value; }
    }
    public bool IsNewDirectionShow
    {
        set { isNewDirectionShow = value; }
    }
    public bool IsRotate
    {
        set { isRotate = value; }
    }
    public Transform CheShenF
    {
        get {return cheShenF ; }
    }
    public Transform CheShenL
    {
        get {return cheShenL; }
    }

    void Awake()
    {
        luenzi1 = transform.Find("BianXingJingGang1/bianxingjinggang-L1/HDM_02_06_tire001");
        luenzi2 = transform.Find("BianXingJingGang1/bianxingjinggang-L1/HDM_02_06_tire002");
        luenzi3 = transform.Find("BianXingJingGang1/bianxingjinggang-L1/HDM_02_06_tire003");
        luenzi4 = transform.Find("BianXingJingGang1/bianxingjinggang-L1/HDM_02_06_tire004");
        cheShen = transform.Find("BianXingJingGang1");
        myLocalScale = cheShen.transform.localScale;
        myLocalPostion = cheShen.transform.localPosition;
        myRotation = cheShen.transform.localRotation;
        uiCamera = GameObject.FindGameObjectWithTag("UICamera").GetComponent<Camera>();
        cheShenF = transform.Find("BianXingJingGang1/bianxingjinggang-F1");
        cheShenL = transform.Find("BianXingJingGang1/bianxingjinggang-L1");
    }

    // Use this for initialization
    void Start()
    {
        cheShenF.gameObject.SetActive(false);
    }

    // Update is called once per frame
    void Update()
    {
        if (isRotate)
        {
            cheShen.Rotate(Vector3.up, 20 * Time.deltaTime);
        }
        showTime -= Time.deltaTime;
        if (showTime <= 0)
        {
            showTime = 8f;
            materialEffect = NGUITools.AddChild(cheShen.gameObject, ResManager.Instance.Load("Prefabs/Effects/GreenCoreAB") as GameObject);
            StartCoroutine(DestroyEffect());
        }
        if (isShow)
        {
            luenzi1.Rotate(Vector3.right, 10);
            luenzi2.Rotate(Vector3.right, 10);
            luenzi3.Rotate(Vector3.right, 10);
            luenzi4.Rotate(Vector3.right, 10);
        }
        if (!isZoom) return;
        TouchMoudel.TouchManager(uiCamera, cheShen, myLocalScale, vehicleInfo);
    }

IEnumerator DestroyEffect()
{
    yield return new WaitForSeconds(0.3f);
        cheShenL.gameObject.SetActive(false);
        cheShenF.gameObject.SetActive(false);
        if (isShow)
        {
            cheShenF.gameObject.SetActive(true);
            isShow = false;
        }
        else
        {
            cheShenL.gameObject.SetActive(true);
            isShow = true;
        }
        Destroy(materialEffect,0.5f);
    }

    /// <summary>
    /// 复位
    /// </summary>
    public void ResetCheShen()
    {
        TouchMoudel.distance = 0;
        TouchMoudel.lastDist = 0;
        TouchMoudel.curDist = 0;
        cheShen.rotation = myRotation;
        cheShen.localPosition = myLocalPostion;
        cheShen.localScale = myLocalScale;
    }

    public void SetCheLunShow()
    {

    }
}
